#include "JsonParser.h"

bool JsonParser::ReadFromFile(const char* filename, char* buffer, int len)
{
	FILE* r = fopen(filename, "rb");
	if (NULL == r)
		return false;
	size_t fileSize = fread(buffer, 1, len, r);
	fclose(r);
	return true;
}

bool JsonParser::LoadFile(const char* filename)
{
	const int BufferLength = 1024 * 500;
	char readBuffer[BufferLength] = {0,};
	if (false == ReadFromFile(filename, readBuffer, BufferLength))
		return false;
	std::string config_doc = readBuffer;
	Json::Reader reader;
	bool parsingSuccessful = reader.parse( config_doc, rootValue );
	if ( !parsingSuccessful )
	{
		std::cout  << "Failed to parse configuration\n"
			<< reader.getFormatedErrorMessages();
		return false;
	}
	return true;
}

JsonParser::JsonParser(void)
{
}


JsonParser::~JsonParser(void)
{
}
